package com.java.simple.study.jvm.memstruct.heap;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhoujunlin
 * @date 2021/12/11
 * @desc 演示堆内存溢出
 * java.lang.OutOfMemoryError: Java heap space
 * -Xmx8m
 **/
public class Demo2_1 {

    public static void main(String[] args) {
        int count = 1;
        try {
            List<String> list = new ArrayList<>();
            String a = "hello world!";
            while (true) {
                list.add(a);
                a = a + a;
                count++;
            }
        } catch (Throwable t) {
            t.printStackTrace();
            System.out.println(count);
        }
    }

}
